package com.west_traveler.viewpager_adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.west_traveler.entity.tab.TabName;
import com.west_traveler.find_page_fragment.AnchorFragment;
import com.west_traveler.find_page_fragment.CategoryFragment;
import com.west_traveler.find_page_fragment.LiveFragment;
import com.west_traveler.find_page_fragment.RankingFragment;
import com.west_traveler.find_page_fragment.RecommendFragment;

import java.util.List;

/**
 * Description: xxx
 * Date:2016年12月02日16:21
 *
 * @author: 刘悦.
 */

public class FindPageMainViewPagerAdapter extends FragmentStatePagerAdapter {

    private List<TabName> tabNames;

    public FindPageMainViewPagerAdapter(FragmentManager fm, List tabNames) {
        super(fm);
        this.tabNames = tabNames;
    }

    @Override
    public Fragment getItem(int position) {
        //根据ViewPager的位置索引，返回对应Fragment的实例
        switch (position) {
            case 0:
                return RecommendFragment.getInstance();
            case 1:
                return CategoryFragment.getInstance();
            case 2:
                return LiveFragment.getInstance();
            case 3:
                return RankingFragment.getInstance();
            case 4:
                return AnchorFragment.getInstance();
            default:
                return RecommendFragment.getInstance();
        }
    }

    @Override
    public int getCount() {
        return tabNames.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return tabNames.get(position).getTitle();
    }
}
